﻿@model LeadMaster.Models.LeadStatus

@using (Ajax.BeginForm(
    "ChangeLeadReason", "Client", null,
    new AjaxOptions
    {
        HttpMethod = "Post"
    }, new { @id = "formChangeReason" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Lead Replacement Request</legend>
@Html.HiddenFor(m => m.LeadStatusID)
@Html.HiddenFor(m => m.BlockID)
@Html.HiddenFor(m => m.LeadFlagsID)
@Html.HiddenFor(m => m.LeadID)
@Html.HiddenFor(m => m.CallCentreID)
@Html.HiddenFor(m => m.LeadDate)
@Html.HiddenFor(m => m.PurchaseOrderID)
@Html.HiddenFor(m => m.VoxFile)
@Html.HiddenFor(m => m.ClientNotes)
<div>
<table class="listtable contactstable" cellspacing="0" cellpadding="0" style="width: 950px;" id="enquirylist">
    <tr>
    <th style="border-style: none"><label>Lead Reason</label></th>
    <td style="border-style: none">
    <select id="Manfield" name="Manfield" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px">
    <option value="0">Which of the following is faulty information....</option>
    @foreach (var item in ViewBag.Manfield)
    {
        if (item != null)
        {
        <option value="@(item)"
        @if (Model.LeadReason.Description == "Mandatory information wrong" && item == Model.Manfield)
        {
		 @:selected
	    }
        >@item.Substring(0, item.Length < 250 ? item.Length : 250)</option>
        }
    }
    </select>
    </td>
    </tr>
    <tr>
    <th style="text-align: left"><label>External Reason</label></th>
    <td style="border-style: none">
    <select id="LeadReasonsID" name="LeadReasonsID" style="font-family: Arial, Helvetica, sans-serif; font-size: 11px">
    <option>Please select a valid Reason...</option>
    @foreach (var item in ViewBag.LeadReasons)
    {
        <option value="@(item.LeadReasonsID)" data-inforequired="@(item.InfoRequired)" data-infoprompt="@(item.InfoPrompt)" id="option@(item.LeadReasonsID)"
        @if (item.LeadReasonsID == Model.LeadReasonsID)
        {
		 @:selected
	}
        >@item.Description</option>
    }
    </select>
    </td>
    </tr>
    <tr>
    <th style="text-align: left">
    <label id="infoheading">Your Notes</label>
    </th>
    <td style="border-style: none" id="cellinfo">
    <label>@Model.Notes</label>
    <textarea class="returnnotes" id="newnote" name="newnote"></textarea>
    </td>
    </tr>
</table>
</div>
@Html.HiddenFor(m => m.Notes)
</fieldset>
}
<input type="hidden" id="hdnNotes" value="@(Model.Notes)" />

<script type="text/javascript">
    $(document).ready(function () {

        $('#Notes').blur(function () {
            if ($('#Notes').val().length < $('#hdnNotes').val().length) {
                $(this).val($('#hdnNotes').val());
            }
        });

        TakeNote("@(Model.LeadReasonsID)");

        $('#LeadReasonsID').change(function () {
            var optionSelected = $(this).val();
            TakeNote(optionSelected);
        });

        function TakeNote(optionSelected) {
            if ($("#option" + optionSelected).data("inforequired") == "True") {
                $('#infoheading').text($("#option" + optionSelected).data("infoprompt"));
            }
        }

        $('#LeadReasonsID').blur(function () {
            if ($('#LeadReasonsID').val() > 1) {
                $('#Manfield').val(0);
            }
        });

        $('#Manfield').change(function () {
            $('#infoheading').text('Incorrect Mandatory Notes');
            $('#LeadReasonsID').val(0);
        });

    });
</script>
